package com.daniel.mi.controller.Impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.daniel.mi.dto.UsersDto;
import com.daniel.mi.enumutil.EnumMqType;
import com.daniel.mi.enumutil.EnumResultCode;
import com.daniel.mi.query.UsersQuery;
import com.daniel.mi.controller.UsersController;
import com.daniel.mi.req.RabbitMqReq;
import com.daniel.mi.result.BaseResponse;
import com.daniel.mi.service.OrderService;
import com.daniel.mi.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

/**
 * @Author zengneng46764
 * @Date 2024/3/6 21:52
 * @Since 1.0.0.0
 * @description: 用户服务对外接口实现
 */
@Controller
@Component
public class UsersControllerImpl implements UsersController {
    @Autowired
    private UsersService usersService;

    @Autowired
    private OrderService orderService;

    @Override
    public Page<UsersDto> page(UsersQuery query) {
        return usersService.page(query);
    }

    /**
     * 消息体为对象。
     *
     * @param
     */
    @Override
    public BaseResponse mqTest(RabbitMqReq req) {
        String message = req.getMessage();
        if(EnumMqType.FONOUT.getCode().equals(message)) {
            orderService.makeFonoutOrder();
        }else if(EnumMqType.DIRECT.getCode().equals(message)){
            orderService.makeDirectOrder();
        }else if (EnumMqType.TOPIC.getCode().equals(message)){
            orderService.makeTopicOrder();
        }else{
            return BaseResponse.fail(EnumResultCode.ILLEGAL_REQUEST.getCode(), "未知类型的消息发布");
        }
        return BaseResponse.success("消息发布成功");
    }

}
